package org.chipu.shared.util.singletons;

import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;

public class DebugUtils {
	private DebugUtils() {/**/}

	@SuppressWarnings("all")
	public static <E> String getInMultipleLines(Collection<E> c, String prefix) {
		if (prefix == null)
			prefix = "";
		if (c.isEmpty())
			return "-";
		StringBuilder s = new StringBuilder();
		for(E o : c)
			if (o instanceof Map)
				getInMultipleLines((Map) o, prefix + "\t");
			else if (o instanceof Collection)
				getInMultipleLines((Collection) o, prefix + "\t");
			else
				s.append("\n").append(prefix).append(o);
		return s.substring(1);
	}

	@SuppressWarnings("all")
	public static <K, V> String getInMultipleLines(Map<K, V> m, String prefix) {
		if (prefix == null)
			prefix = "";
		if (m.isEmpty())
			return "-";
		StringBuilder s = new StringBuilder();
		for(Entry<K, V> o : m.entrySet())
			if (o.getValue() instanceof Map)
				s.append("\n").append(prefix).append(o.getKey()).append("\n").append(prefix)
					.append(getInMultipleLines((Map) o.getValue(), prefix + "\t").substring(prefix.length()));
			else if (o.getValue() instanceof Collection)
				getInMultipleLines((Collection) o, prefix + "\t");
			else
				s.append("\n").append(prefix).append(o);
		return s.substring(1);
	}
}